<?php
if ( !defined( "IN_UCHOME" ) ) exit( "Access Denied" );
class feeds
{
	var $template = array(
		0 => "<b>{actor}</b> 申请了加入活动{subject}，在等待审核",
		1 => "<b>{actor}</b> 申请了加入活动{subject}，并通过了审核",
		2 => "<b>{actor}</b> 对活动{subject}比较感兴趣",
		3 => "<b>{actor}</b> 在活动{subject}中上传了{photo}",
		4 => "<b>{actor}</b> 对活动{subject}发表了评论",
	);

	function add($param, $tpl = 0, $user = array())
	{
		$feed = new feeds;
		$fs = array();
		$fs['icon'] = 'event';
		$fs['title_template'] = $feed->template[$tpl];
		$fs['title_data'] = $param;
		/*
		$fs['title_data'] = array(
			'movie'=> "《<a href='movie.php?ac=show&id={$id}'>{$mv['name']}</a>》",
			'subject' => "<span class='{$class}' {$style}></span>"
		);*/

		return $feed->feed_add($fs['icon'], $fs['title_template'], $fs['title_data'], $user);
	}

	//事件发布
	function feed_add($icon, $title_template='', $title_data=array(), $user = array()) {
		global $_SGLOBAL;
		if(empty($_SGLOBAL['supe_uid'])) return false;
		$body_data = array();
		$feedarr = array(
			'appid' => UC_APPID,
			'icon' => $icon,
			'uid' => empty($user) ? $_SGLOBAL['supe_uid'] : $user['uid'],
			'username' => empty($user) ? $_SGLOBAL['supe_username'] : $user['username'],
			'dateline' => $_SGLOBAL['timestamp'],
			'title_template' => $title_template,
			'body_template' => '',
			'body_general' => '',
			'image_1' => '',
			'image_1_link' => '',
			'image_2' => '',
			'image_2_link' => '',
			'image_3' => '',
			'image_3_link' => '',
			'image_4' => '',
			'image_4_link' => '',
			'target_ids' => '',
			'friend' => ''
		);
		$feedarr = sstripslashes($feedarr);//去掉转义
		$feedarr['title_data'] = serialize(sstripslashes($title_data));//数组转化
		$feedarr['body_data'] = serialize(sstripslashes($body_data));//数组转化
		$feedarr['hash_template'] = md5($feedarr['title_template']."\t".$feedarr['body_template']);//喜好hash
		$feedarr['hash_data'] = md5($feedarr['title_template']."\t".$feedarr['title_data']."\t".$feedarr['body_template']."\t".$feedarr['body_data']);//合并hash
		$feedarr = saddslashes($feedarr);//增加转义
		return inserttable('feed', $feedarr, 1);
	}
}
?>